#ifndef __HTTP_SEREVR_H
#define __HTTP_SEREVR_H

#include <stdio.h>
#include <stdlib.h>
#include <evhttp.h>
#include <event.h>
#include <string.h>
#include <iostream>
#include <string>
#include <sys/time.h>
#include <unistd.h>
#include <vector>
#include <mutex>
#include <thread>
#include <condition_variable>
#include <time.h>

#include "event2/http.h"
#include "event2/event.h"
#include "event2/buffer.h"
#include "event2/bufferevent.h"
#include "event2/bufferevent_compat.h"
#include "event2/http_struct.h"
#include "event2/http_compat.h"
#include "event2/util.h"
#include "event2/listener.h"

#include <sstream>
#include <fstream>
#include <string>
#include <functional>

#include <task_logic.h>

string ptree_to_string(ptree &pt);
void set_succeed_return(ptree &pt);
void set_error_return(ptree &pt);
void generic_handler(struct evhttp_request *req, void *arg);
void http_default_handler(struct evhttp_request *req);
void http_get_handler(struct evhttp_request *req);
void http_post_handler(struct evhttp_request *req);

ptree getMac();
string get_map_list();
ptree del_map(string map_name);
bool get_map_png(string mapUri, struct evbuffer *databuf,int &code, string &reason);
bool get_map_pcd(string mapUri, struct evbuffer *databuf,int &code, string &reason);
bool get_map_pgm(string mapUri, struct evbuffer *databuf,int &code, string &reason);

ptree set_param(char buf[]);
ptree get_param(string map_name);
ptree edit_map(string map_name);
string load_map(string map_name);
ptree get_load_map_status();

ptree get_origin_point(string map_name);

ptree add_navi_point(char buf[]);
ptree del_navi_point(string map_name, string point_name);
ptree rename_navi_point(char buf[]);
ptree add_navi_path(char buf[]);
ptree del_navi_path(string map_name, string path_name);
ptree get_task();
ptree add_task(char buf[]);
ptree edit_task(char buf[]);
ptree del_task(string map_name, string path_name);
ptree get_default_task(string map_name);
ptree set_default_task(char buf[]);
ptree del_default_task(string map_name);
ptree set_head_mode(string cmd);
ptree set_move_cmd(char buf[]);
ptree set_charge_cmd(string cmd);
ptree set_manual_mode(string cmd);
ptree navi_to_point(char buf[]);
ptree navi_to_dest(char buf[]);
ptree navi_along_path(char buf[]);
ptree get_status();
ptree get_gps_data();
ptree get_alarm(string map_name);
ptree get_log(string map_name);
ptree update_navi_info();

ptree init_localization(string map_name, string init_point_name);
ptree get_init_status();
ptree set_navi_speed(string level);
ptree get_task_status();
ptree start_task(char buf[]);
ptree stop_task();
ptree update_task_info();

ptree connect();
ptree set_control_mode(string mode);
ptree download_file(char buf[]);

ptree get_3d_lidar();
ptree get_2d_lidar();
ptree get_camera();

ptree get_sonar();
ptree get_infra();
ptree get_key();
ptree get_imu();
ptree get_gps();
ptree get_odom();
ptree get_rfid();
ptree get_uwb();
ptree set_safe_area(string r1,string r2,string r3);
ptree set_init_point(char buf[]);
ptree set_calibration_point(char buf[]);
ptree set_work_point(char buf[]);
ptree set_charge_point(char buf[]);
ptree set_navi_point(char buf[]);
ptree set_user_point(char buf[]);
ptree set_navi_path(char buf[]);
ptree set_virtual_wall(char buf[]);
ptree set_virtual_wall_point(char buf[]);
ptree set_user_path(char buf[]);
ptree set_user_path_point(char buf[]);
ptree set_slow_area(char buf[]);
ptree set_slow_area_point(char buf[]);
ptree set_stop_area(char buf[]);
ptree set_stop_area_point(char buf[]);
ptree set_user_area(char buf[]);
ptree set_user_area_point(char buf[]);

string get_navi_point();
string get_init_point(string map_name);
string get_calibration_point(string map_name);
string get_navi_point(string map_name);
string get_work_point(string map_name);
string get_charge_point(string map_name);
string get_user_point(string map_name);

string get_navi_path(string map_name);
string get_virtual_wall(string map_name);
string get_virtual_wall_point(string map_name);
string get_user_path(string map_name);
string get_user_path_point(string map_name);

string get_slow_area(string map_name);
string get_stop_area(string map_name);
string get_user_area(string map_name);
string get_slow_area_point(string map_name);
string get_stop_area_point(string map_name);
string get_user_area_point(string map_name);

ptree set_mapping_mode(string map_name, string mode);
ptree start_scan();
ptree cancel_scan();
ptree finish_scan();
ptree get_scan_status();
ptree start_mapping();
ptree cancel_mapping();
ptree get_mapping_status();
ptree global_position();
ptree initial_position(char buf[]);
ptree start_route(char buf[]);
ptree get_running_status();
ptree pause_task();
ptree resume_task();
ptree stop_task();
#endif